package com.yutel.http.HttpServer.handler;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.yutel.http.HttpServer.ParameterUtil;

public class ServerInfoHandler implements HttpHandler {

	@Override
	public void handle(HttpExchange he) throws IOException {
		System.out.println("ServerInfoHandler()");
		Headers headers = he.getRequestHeaders();
		for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
			System.out.println("req:key=" + entry.getKey() + ",value="
					+ entry.getValue());
		}
		String response = ParameterUtil.getServerInfo();
		he.sendResponseHeaders(200, response.length());
		Headers responseHeaders = he.getResponseHeaders();
		for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) {
			System.out.println("res:key=" + entry.getKey() + ",value="
					+ entry.getValue());
		}
		OutputStream os = he.getResponseBody();
		os.write(response.getBytes());
		os.close();
	}

}
